<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/10/27
 * Time: 10:16
 */

namespace zhtfrontend\modules\sitepadapi\controllers;

use zhtfrontend\models\datas\OrdercourseHistory;
use zhtfrontend\models\datas\OrderSales;
use zhtfrontend\modules\sitepadapi\components\rest\ActiveController;
use yii\data\ActiveDataProvider;

class CommentmechanicController extends ActiveController
{
    public $modelClass = 'zhtfrontend\models\datas\Mechanic';

    public $serializer = [
        'class' => 'zhtfrontend\modules\sitepadapi\components\rest\Serializer',
        'collectionEnvelope' => 'items',
    ];

    public function actions()
    {
        $actions = parent::actions();
        unset($actions['index'], $actions['create'], $actions['update'], $actions['delete'], $actions['view']);
        return $actions;
    }

    public function actionIndex()
    {
        $modelClass = $this->modelClass;
        $query = $modelClass::find();
        return new ActiveDataProvider([
            'query' => $query
        ]);
    }

    public function actionFindbycid($customer_id)
    {
        $order_sales_id = OrdercourseHistory::find()->select('order_sales_id')->where(['user_id' => $customer_id])->asArray()->column();
        $mechanic_id = OrderSales::find()->select('mechanic_id')->where(['in', 'id', $order_sales_id])->andWhere(['type' => 0])->asArray()->column();
        $modelClass = $this->modelClass;
        $query = $modelClass::find()->where(['in', 'id', $mechanic_id]);
        return new ActiveDataProvider([
            'query' => $query
        ]);
    }

    public function actionCreate()
    {

    }
}